Welcome![Sign In][Sign Up]
Location:
Search - diffuse light

Search list

[Other resource全局光照环境中的逆向绘制

Description: 提出一种恢复场景中所有物体的反射特性的方法.对漫反射、各向同性反射和各向异性反射纹理 面的纹理恢复也作了深入研究 高光和阴影的影响也能基本去除.-A scene restore all objects, the reflective properties of the method. The diffuse reflectance, isotropic and anisotropic reflex reflector surface texture Texture resume also made in-depth research on the impact of light and shadow can remove basic.
Platform: | Size: 236104 | Author: 隼鼻梁 | Hits:

[Internet-Network用D3D模拟地月系

Description:

 

 

 

  一、建立空窗体

  新建一个工程,添加引用,并导入名称空间。

  加入一个设备对象变量:

private Microsoft.DirectX.Direct3D.Device device = null;

  添加初始化图形函数,并在这里面对设备对象进行实例化:

public void InitializeGraphics()
{
 PresentParameters presentParams = new PresentParameters();
 presentParams.Windowed = true;
 presentParams.SwapEffect = SwapEffect.Flip;
 presentParams.AutoDepthStencilFormat = DepthFormat.D16;
 presentParams.EnableAutoDepthStencil = true;
 device = new Microsoft.DirectX.Direct3D.Device(0, Microsoft.DirectX.Direct3D.DeviceType.Hardware, this,  CreateFlags.HardwareVertexProcessing, presentParams);
}

  当程序执行时,需要绘制场景,代码在这个函数里:

public void Render()

{
 // 清空设备,并准备显示下一帧。
 device.Clear(ClearFlags.Target | ClearFlags.ZBuffer, Color.Black , 1.0f, 0);
 // 设置照相机的位置
 SetupCamera();
 //开始场景
 device.BeginScene();
 if(meshLoaded)
 {
  mesh.Render(meshLoc);
 }
 device.EndScene();
 //显示设备内容。
 device.Present();
}

  设置照相机的位置:

private void SetupCamera()
{
 device.Transform.Projection = Matrix.PerspectiveFovLH((float)Math.PI / 4, this.Width / this.Height, 1.0f, 1000.00f);
 device.Transform.View = Matrix.LookAtLH(new Vector3(0.0f ,0.0f, 20.0f), new Vector3(0.0f,0.0f, 0.0f), new Vector3(0,1,0));
}

  现在改变主函数,调用我们写的初始化函数,并显示场景:

[STAThread]

static void Main()
{
 using (Form1 EarthForm = new Form1())
 {
  EarthForm.InitializeGraphics();
  EarthForm.Show();

  while(EarthForm.Created)
  {
   EarthForm.Render();
   Application.DoEvents();
  }
  EarthForm.Dispose();
}

  运行程序,会显示一个空的窗体。

  二、加入地球:

  在这一步里需创建一个3D网格对象,来作为要显示的地球,为此,在工程中新加入一个类Earth,此类可以包含所创建的网格对象的信息。

  加入一些相关变量,含义见注释:

public class Earth : BaseEarth
{
 private Material[] mMaterials; //保存材质
 private Texture[] mTextures; //保存纹理
 private Matrix locationOffset; //用来保存网格对象的相对位置
 private Mesh mMesh = null; //三角形网格对象
 private Device meshDevice; //需要显示在哪个设备上。
}

  在构造函数中,把Device设备拷贝到私有成员变量,这样就可以在这个类的其它方法内使用它,另外就是把位置变量进行赋值:

public Earth(ref Device device, Matrix location): base(ref device)
{
 meshDevice = device;
 locationOffset = location;
}

  下面这个函数是装入.X文件。

public bool LoadMesh(string meshfile)
{
 ExtendedMaterial[] mtrl;
 try
 {
  // 装载文件
  mMesh = Mesh.FromFile(meshfile, MeshFlags.Managed, meshDevice, out mtrl);
  // 如果有材质的话,装入它们
  if ((mtrl != null) && (mtrl.Length > 0))
  {
   mMaterials = new Material[mtrl.Length];
   mTextures = new Texture[mtrl.Length];

   // 得到材质和纹理

   for (int i = 0; i < mtrl.Length; i++)
   {
    mMaterials[i] = mtrl[i].Material3D;
    if ((mtrl[i].TextureFilename != null) && (mtrl[i].TextureFilename != string.Empty))

 

    {
     //前面得到的纹理的路径是相对路径,需要保存的是绝对路径,通过应用程序路径可以获得
     mTextures[i] = TextureLoader.FromFile(meshDevice, @"..\..\" + mtrl[i].TextureFilename);
    }
   }
  }
  return true;
 }
 catch
 {
  return false;
 }
}

  在这个方法内,使用Mesh.FromFile()这个方法,从给定的文件名中找到.X文件,并装入相关数据,一旦数据格式设置完成,可以从此文件中找到材质和贴图信息,并把它存放在数组中,并通过文件路径,得到纹理文件文件的路径,最后返回真值,如果整个过程出现错误,返回假值。

  下面这个Render()方法,是把此对象,即地球显示在设备对象上,此方法较简单,通过变形操作来得到网格对象的X,Y,Z坐标,接着设置网格对象的材质和纹理,最后,将每个材质和纹理应用到每个网格。

public void Render(Matrix worldTransform)
{
 /把位置变为世界坐标
 meshDevice.Transform.World = Matrix.Multiply(locationOffset, worldTransform);
 //绘制网格
 for (int i = 0; i < mMaterials.Length; i++)
 {
  meshDevice.Material = mMaterials[i];
  meshDevice.SetTexture(0, mTextures[i]);
  mMesh.DrawSubset(i);
 }
}

  现在回到窗体代码中,添加引用网格对象的相关变量:

private Earth mesh = null;
private Matrix meshLoc;
private bool meshLoaded = false;

  在图形初始化函数中,需要对网格对象进行初始化。加入下面的代码:

meshLoc = Matrix.Identity;
meshLoc.M41 = 2.0f;
mesh = new Earth(ref device, meshLoc);
if (mesh.LoadMesh(@"..\..\earth.x"))
{
 meshLoaded = true;
}

  代码第一句把网格对象的位置定为原点,接着偏移X轴2个单位,接下来从文件中得到此.X文件。如果成功设置,meshLoaded置为真。注意,这里有一个.X文件,在源代码中有此文件。

 


  在设置相机的函数中,加入一盏灯光:

device.Lights[0].Type = LightType.Directional;
device.Lights[0].Diffuse = Color.White;
device.Lights[0].Direction = new Vector3(0, -1, -1);
device.Lights[0].Update();
device.Lights[0].Enabled = true;


  此灯光较简单,仅为一个直射型白光灯。

最后,在Render()方法中,调用网格对象的Render()方法,以显示地球。

 

  三、使地球旋转

  前面用一个网格对象来建立地球,但此类没有平移,旋转及缩放等方法,下面就加入这些方法,因为这些方法具有通用性,因此可以新建一个类,把这些方法写在这些类中,使地球对象成为它的派生类。

  在工程中新添加一个类:BaseEarth;

  加入进行平移、旋转、缩放的变量:

 

private float xloc = 0.0f;
private float yloc = 0.0f;
private float zloc = 0.0f;
private float xrot = 0.0f;
private float yrot = 0.0f;
private float zrot = 0.0f;
private float xscale = 1.0f;
private float yscale = 1.0f;
private float zscale = 1.0f;


  加入相应的属性代码:

 

public float XLoc
{
 get
 {
  return xloc;
 }
 set
 {
  xloc = value;
 }
}
…………

 

  在Render()虚函数中,应用平移、旋转及缩放。
 

public virtual void Render()
{
 objdevice.MultiplyTransform(TransformType.World,Matrix.Translation(xloc, yloc, zloc));
 objdevice.MultiplyTransform(TransformType.World,Matrix.RotationAxis(new Vector3(1.0f, 0.0f, 0.0f), xrot));
 objdevice.MultiplyTransform(TransformType.World,Matrix.RotationAxis(new Vector3(0.0f, 1.0f, 0.0f), yrot));
 objdevice.MultiplyTransform(TransformType.World,Matrix.RotationAxis(new Vector3(0.0f, 0.0f, 1.0f), zrot));
 objdevice.MultiplyTransform(TransformType.World,Matrix.Scaling(xscale, yscale, zscale));
 return;
}

 

  现在回到地球类,需要将其改为新类的派生类,同时更改构造函数,另外,在Render()方法中,应先调用基类的Render()方法:


public override void Render()
{
 base.Render();
 //把位置变为世界坐标
 // meshDevice.Transform.World = Matrix.Multiply(locationOffset, worldTransform);
 //绘制网格
 。。。。。。
}

 


  现在,由于在基类中可以设置对象位置,因此,可以把与locationOffset相关,即与设置位置的变量及语句注释掉。

  四、加入月球

  在这一步加入月球,实际上是再创建一个网格对象新实例,只是把纹理进行更改即可,为了代码模块性更好,把两个对象放在一个新类CModel中,在工程中新添加一个类CModel,并声明对象实例。


public class cModel
{
 private cMeshObject mesh1 = null;
 private cMeshObject mesh2 = null;
 private bool modelloaded;
}


  把窗口代码中的Load()事件,放在CModel中,这次不仅生成了地球,而且生成了月球。

 


public void Load(ref Device device)
{
 mesh1 = new Earth(ref device);
 mesh2 = new Earth(ref device);
 if (mesh1.LoadMesh(@"..\..\earth2.x"))
 {
  modelloaded = true;
 }
 else
 {
  modelloaded = false;
 }
 if (mesh2.LoadMesh(@"..\..\moon.x"))
 {
  mesh2.XLoc += 20.0f;
  modelloaded = true;
 }
 else
 {
  modelloaded = false;
 }
}

 

  下面的Update()方法中,参数dir 用来判断是顺时针旋转还是逆时针旋转,另外,地球和月球绕Y轴增加的角度大小不同,也就决定了二者旋转的速度不同。


public void Update(int dir)
{
 if(dir > 0)
 {
  mesh1.YRot += 0.02f;
  mesh2.YRot += 0.05f;
 }
 else if(dir < 0)
 {
  mesh1.YRot -= 0.02f;
  mesh2.YRot -= 0.05f;
 }
}


  在下面的render()方法中,生成显示月球和地球:

 


public void Render(ref Device device)
{
 device.Transform.World = Matrix.Identity;
 if(modelloaded)
 {
  mesh1.Render();
  mesh2.Render();
 }
}


  把窗口代码中的加入灯光的方法,也放在此类中:


public void LoadLights(ref Device device)
{
 device.Lights[0].Type = LightType.Directional;
 device.Lights[0].Diffuse = Color.White;
 device.Lights[0].Position = new Vector3(0.0f, 0.0f, 25.0f);
 device.Lights[0].Direction = new Vector3(0, 0, -1);
}
public void Light(ref Device device)
{
 device.Lights[0].Update();
 device.Lights[0].Enabled = true;
}


  五、与鼠标交互操作

  为了实现与键盘、鼠标交互,新添加一个类:CMouse,添加引用Microsoft.DirectX.DirectInput,并添加命名空间。加入相关变量:


private Microsoft.DirectX.DirectInput.Device mouse = null;
public System.Threading.AutoResetEvent MouseUpdated;
private float x, y, z = 0.0f;
private byte[] buttons;

 

  在下面的构造函数代码中,首先创建鼠标设备,并初始化回调事件:


public CMouse(System.Windows.Forms.Control control)
{
 mouse = new Microsoft.DirectX.DirectInput.Device(SystemGuid.Mouse);
 mouse.SetCooperativeLevel(control, CooperativeLevelFlags.Background | CooperativeLevelFlags.NonExclusive);
 mouse.Properties.AxisModeAbsolute = false;
 MouseUpdated = new System.Threading.AutoResetEvent(false);
 mouse.SetEventNotification(MouseUpdated);
 mouse.Acquire();
 Update();

 


  下面的Update()方法中获得鼠标的坐标值,并赋给私有成员变量:

public void Update()
{
 MouseState state = mouse.CurrentMouseState;
 x = state.X;
 y = state.Y;
 z = state.Z;
 buttons = state.GetMouseButtons();
}


  还需要有一个函数来检测鼠标左键是否按下:

 


public bool LeftButtonDown
{
 get
 {
  bool a;
  return a = (buttons[0] != 0);
 }
}


  六、大结局

  现在已经做完了准备工作,返回到窗口代码中,需要对这里的代码重新进行一些调整:

  在图形初始化函数中创建一个CModel类及CMouse类:

 

private CModel model = null;
private CMouse mouse = null;
private bool leftbuttondown = false;
private float mousexloc;

 

  添加对鼠标初始化的方法:

 

网管联盟bitsCN@com


public void InitializeInput()
{
 mouse = new CMouse(this);
}


  添加UpdateInputState()方法,当按下鼠标左键时,将leftbuttondown值设置为真,当鼠标抬起时,将mousexloc置0:


private void UpdateInputState()
{
 mouse.Update();
 if (mouse.LeftButtonDown)
 {
  if(leftbuttondown == false)
  {
   mousexloc = 0.0f;
   leftbuttondown = true;
  }
  else
  {
   mousexloc = -mouse.X;
  }
 }
 else
 {
  leftbuttondown = false;
  mousexloc = 0.0f;
 }
}


  在此程序中,只对X值进行了操作,即只能左右转。

  Render()方法更新如下:

public void Render()
{
 UpdateInputState();
 device.Clear(ClearFlags.Target | ClearFlags.ZBuffer, Color.DarkGray, 1.0f, 0);
 SetupCamera();
 device.BeginScene();
 model.Update((int)mousexloc);
 model.Light(ref device);
 model.Render(ref device);
 device.EndScene();
 device.Present();
}

 

  最后更改Main()主函数:


static void Main()
{
 using (Form1 EarthForm = new Form1())
 {
  EarthForm.InitializeGraphics();
  EarthForm.InitializeInput();
  EarthForm.Show();
  while(EarthForm.Created)
  {
   EarthForm.Render();
   Application.DoEvents();
  }
  EarthForm.Dispose();
 }
 


Platform: | Size: 11817 | Author: mantoutou | Hits:

[Software Engineering全局光照环境中的逆向绘制

Description: 提出一种恢复场景中所有物体的反射特性的方法.对漫反射、各向同性反射和各向异性反射纹理 面的纹理恢复也作了深入研究 高光和阴影的影响也能基本去除.-A scene restore all objects, the reflective properties of the method. The diffuse reflectance, isotropic and anisotropic reflex reflector surface texture Texture resume also made in-depth research on the impact of light and shadow can remove basic.
Platform: | Size: 235520 | Author: 隼鼻梁 | Hits:

[Othersimpleraytracer_v1_0

Description: 用VC++实现光线最综算法,考虑了光的漫反射和光的镜面反射-With VC++ Realize the light most mechanized algorithm, consider a light diffuse reflectance and specular reflection of light
Platform: | Size: 1870848 | Author: maolimin | Hits:

[OpenGL program2.2

Description: opengl光照与材质之材质 环境光 漫反射光 镜面反射光-opengl light and texture of the material ambient light diffuse reflectance optical mirror reflected light
Platform: | Size: 100352 | Author: 连连 | Hits:

[3D GraphicZBuffer

Description: 光线跟踪算法实现,VC2005下编写的MFC程序。本程序实现高光、镜面反射、漫反射和折射效果。-Ray-tracing algorithm, VC2005 prepared MFC procedures. This procedure to achieve high light, specular reflection, diffuse reflection and refraction effects.
Platform: | Size: 82944 | Author: lemon lee | Hits:

[OpenGL programopengl_project

Description: 一个关于ambient light ,diffuse light, and specular light, and depth cueing , and trangulation 的project, 编译已通过!! 比较经典的一个关于图形的project!欢迎大家下载学习,里面还有MACH BAND和 opengl 的一些其他问题-this projects includes the effect of ambient light , diffuse light, and specular light ,and the depth cueing and the spot light etc..
Platform: | Size: 861184 | Author: 李平 | Hits:

[Otherball

Description: 球的光照模型算法,绘制球体,给球体施加环境光、漫反射光和镜面反射光-Global illumination model algorithm, drawn ball to ball to impose environmental light, diffuse light and specular reflection of light
Platform: | Size: 1024 | Author: chencl | Hits:

[CSharpTutorial2_Diffuse

Description: 关于如何设置漫反射的光的设置 XNA里使用-how to set the diffuse light in XNA
Platform: | Size: 1103872 | Author: zt1h | Hits:

[Game EngineXNA-light-shaders

Description: diffuse + specular lighting shader for xna4
Platform: | Size: 3072 | Author: carlosh | Hits:

[OpenGL programlighting_diffuse

Description: 3D 图形学, 一个漫反射光的例子。 一个漫反射光线模型的演示-3D graphics, an example of a diffuse light. A demonstration model of diffuse light
Platform: | Size: 71680 | Author: liuweiguang | Hits:

[OpenGL programopengl_qt_linghting_blending

Description: 本次实验主要是学习下opengl中光照的使用方法,opengl中的光照分为环境光,漫射光,镜面光,反射光4种,这里主要是学习环境光和漫射光的设置,同时对比下opengl中支持的几种纹理滤波方式的效果,另外也可以加入色彩融合效果。这次实验是将一个木箱纹理贴到一个立方体上,然后我们在空间屏幕正外方设置了一个光源,可以用键盘的L键来控制该光源的开启和关闭;用F键来旋转程序中用到的3种滤波方式,按下F键后,依次切换该3种方式;用PageUp键来使物体离观察者越来越远,相反,用PageDown来使物体离我们越来越近;使用向上光标键加快物体旋转的速度,向下光标键减小物体旋转的速度。   开发环境:windows+QtCreator2.5.1+Qt4.8.2-The experiment is mainly the use of light in learning under opengl, opengl light into the ambient light, diffuse light, specular light, reflected light, learning environment light and diffuse light settings while contrast under opengl in support of several on the effect of texture filtering, addition can also add color fusion effect. This experiment is a wooden texture to a cube, and then we have a light source is set in space screen positive outward, L key can use the keyboard to control the opening and closing of the light source with the F key rotation procedures used three kinds of filtering the way, press the F key, followed by switching the 3 ways PageUp key to make objects farther and farther away from the observer, on the contrary, PageDown to make objects closer and closer using the accelerating the speed of rotation of the object, the up cursor key down cursor keys to reduce the speed of rotation of the objects. Development Environment: windows+QtCreator2.5.1+Qt4.8.2
Platform: | Size: 2189312 | Author: wuwei | Hits:

[OpenGL programOpenGL-Light

Description: 2. 在代码中添加光照函数,要求如下: (1)使用光源1 (2)设置光源的环境光、漫反射光以及镜面反射光颜色 (3)设置光源位置 (4)设置物体材质属性,包括:环境光、漫反射以及镜面反射系数(两个三维对象材质属性不能相同);对其中一个三维对象设置其表面发射项 -Light function, add code requirements are as follows: (1) the use of the light source 1 (2) Set the light source of ambient light, diffuse, and specular reflection light color (3) to set the position of the light source (4) to set the object material properties, including : ambient, diffuse reflection and specular reflection coefficient (two three-dimensional object material properties can not be the same) setting its surface-emitting items for which a three-dimensional object
Platform: | Size: 367616 | Author: yyy | Hits:

[DirextXDX-Project-7

Description: 《DirectX 8 教程》及配套代码 第七章:灯光与材质 Introduction (序) DirectX Lighting vs. Real World Lighting (DX光照 对 真实世界光照) Attributes of a light (光的属性): Position (位置) Direction (方向) Range (范围) Attenuation (衰减) Diffuse Light (漫反射) Ambient Light (环境光) Specular Light (镜面反射) Types of lighting (光的类型): Ambient Light (环境光) Point Light (点光源) Directional Light (直射光) -Chapter VII of the " DirectX 8 tutorial" and supporting code: Lighting and Material Introduction (sequence) DirectX Lighting vs Real World Lighting the (DX illumination light of the real world) Attributes of a light (attributes): Position (position) Direction ( direction) Range (range) Attenuation (attenuation) the Diffuse Light (diffuse reflectance) Ambient Light (ambient light) Specular Light (specular reflection) Types of lighting (light type): Ambient Light (environmental light) Point Light (point source) Directional Light (direct light)
Platform: | Size: 12288 | Author: liuyan | Hits:

[ApplicationsXNA-light-shaders

Description: diffuse + specular lighting shader for xna4-diffuse+ specular lighting shader for xna4
Platform: | Size: 3072 | Author: ecrktonsH | Hits:

[OpenGL programdonghua

Description: 设置了两个光源,一个是漫反射的蓝色点光源,另一个是红色聚光光源,它们都照在一个球体上,产生亮斑。-Set up two sources, one is blue diffuse light source, and the other is a red spot light, they are shining on a sphere, producing bright spots.
Platform: | Size: 6144 | Author: 高勇 | Hits:

[OpenGL programOPENGL_LIGHT

Description: 在opengl实现光照效果,包括环境光、漫射光、镜面光-Achieve lighting effects in opengl, including ambient light, diffuse light, specular light
Platform: | Size: 9183232 | Author: 陈鹏飞 | Hits:

[OpenGL programLight_Programming

Description: 计算机图形学OpenGL编程环境光、漫反射光、镜面反射光、材质高光系数对图像的作用的编程源代码-Computer Graphics OpenGL programming environment, diffuse light, specular, high extinction coefficient of the material on an image of the programming source code
Platform: | Size: 2178048 | Author: 安容巧 | Hits:

[Disk ToolsDiffusjectur

Description: Diffuse objects generally tell us little about the surround- ing lighting, since the radiance they reflect blurs together incident lighting many directions. In this paper we discuss how occlusion geometry can help invert diffuse reflectance to recover lighting or surface albedo. Self- occlusion in the scene can be regarded as a form of coding, creating high frequencies that improve the conditioning of diffuse light transport. Our analysis builds on a basic obser- vation that diffuse reflectors with sufficiently detailed geome- try can fully resolve the incident lighting-Diffuse objects generally tell us little about the surround- ing lighting, since the radiance they reflect blurs together incident lighting many directions. In this paper we discuss how occlusion geometry can help invert diffuse reflectance to recover lighting or surface albedo. Self- occlusion in the scene can be regarded as a form of coding, creating high frequencies that improve the conditioning of diffuse light transport. Our analysis builds on a basic obser- vation that diffuse reflectors with sufficiently detailed geome- try can fully resolve the incident lighting
Platform: | Size: 1864704 | Author: yangs | Hits:

[matlabmengtekaluo

Description: 蒙特卡洛光子模拟程序,可以设定介质的层数、折射率、厚度等,程序可以输出漫反射光、漫透射光、准直透射光的强度(Monte Carlo photon simulation program, which can set the number of layers, refractive index, thickness, etc. of the medium, can output the intensity of diffuse light, diffuse light and quasi direct light)
Platform: | Size: 12288 | Author: woyaokaobo | Hits:
« 12 3 »

CodeBus www.codebus.net